﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
    public abstract class RenderEffect : MonoBehaviour
    {
        private LinkedListNode<RenderEffect> renderNode;
        public  abstract bool IsStatic { get; }
        public abstract RenderEffectManager RenderEffectMgr { get; }
        public abstract bool IsTakeEffect(NirvanaRenderer renderer);

        protected void Awake()
        {
            if(this.IsStatic && Application.isPlaying)
            {
                this.renderNode = this.RenderEffectMgr.AddStatic(this);
            }
            else
            {
                this.renderNode = this.RenderEffectMgr.AddDynamic(this);
            }
        }
        protected void OnEnable()
        {
            if (this.renderNode != null) return;
            if (this.IsStatic && Application.isPlaying)
            {
                this.renderNode = this.RenderEffectMgr.AddStatic(this);
            }
            else
            {
                this.renderNode = this.RenderEffectMgr.AddDynamic(this);
            }
        }

        protected void OnDisable()
        {
            if (this.renderNode == null) return;
            if (this.IsStatic && Application.isPlaying)
            {
               this.RenderEffectMgr.RemoveStatic(renderNode);
            }
            else
            {
                this.RenderEffectMgr.RemoveDynamic(renderNode);
            }
            this.renderNode = null;
        }
        protected void OnDestroy()
        {
            if (this.renderNode != null)
            {
                if (this.IsStatic && Application.isPlaying)
                {
                    this.RenderEffectMgr.RemoveStatic(renderNode);
                }
                else
                {
                    this.RenderEffectMgr.RemoveDynamic(renderNode);
                }
                this.renderNode = null;
            }

        }

    }
}

